using Com.SharpZebra.Commands.Codes;
using NUnit.Framework;

namespace Com.SharpZebra.UnitTests.Commands
{
    [TestFixture]
    public class ZebraCommandsTestFixture
    {
        private readonly string START_NEW_PRINT_COMMAND = "\nN";
        private readonly string PRINT_ONE_COPY_COMMAND = "P1\r\n";

        [Test]
        public void ShouldAddPrefixNeededToClearThePrinterAndEndItWithAPrintOneCopyCommand()
        {
            ZebraCommands zebraCommands = new ZebraCommands();
            string zebraInstruction = zebraCommands.ToZebraInstruction();
            Assert.IsTrue(zebraInstruction.StartsWith(START_NEW_PRINT_COMMAND));
            Assert.IsTrue(zebraInstruction.EndsWith(PRINT_ONE_COPY_COMMAND));
        }

        [Test]
        public void ShouldSeparateEachCommandWithANewLineCharacter()
        {
            ZebraCommands zebraCommands = new ZebraCommands();
            zebraCommands.Add(
                ZebraCommands.TextCommand(0, 0, ElementRotation.NO_ROTATION, StandardZebraFont.SMALL, 0, 0, true,
                                          "something"));
            string decoratedZebraCommmand =
                zebraCommands.ToZebraInstruction().Replace(START_NEW_PRINT_COMMAND, "").Replace(PRINT_ONE_COPY_COMMAND,
                                                                                                "");
            Assert.IsTrue(decoratedZebraCommmand.EndsWith("\r\n"));
        }

        [Test]
        public void TextInstructionShouldGenerateTheProperString()
        {
            Assert.AreEqual("A0,1,0,2,2,3,R,\"anything\"",
                            ZebraCommands.TextCommand(0, 1, ElementRotation.NO_ROTATION, StandardZebraFont.SMALL, 2, 3,
                                                      true, "anything").ToZebraInstruction());
            Assert.AreEqual("A0,1,3,2,2,3,N,\"anythingaswell\"",
                            ZebraCommands.TextCommand(0, 1, ElementRotation.ROTATE_270_DEGREES, StandardZebraFont.SMALL,
                                                      2, 3, false, "anythingaswell").ToZebraInstruction());
            Assert.AreEqual("A6,7,0,4,9,8,R,\"anything\"",
                            ZebraCommands.TextCommand(6, 7, ElementRotation.NO_ROTATION, StandardZebraFont.LARGE, 9, 8,
                                                      true, "anything").ToZebraInstruction());
        }

        [Test]
        public void LineDrawBlackCommandShouldGenerateTheProperString()
        {
            Assert.AreEqual("LO50,200,400,20", ZebraCommands.BlackLine(50, 200, 400, 20).ToZebraInstruction());
            Assert.AreEqual("LO10,20,30,40", ZebraCommands.BlackLine(10, 20, 30, 40).ToZebraInstruction());
        }


        [Test]
        public void LineDrawWhiteCommandShouldGenerateTheProperString()
        {
            Assert.AreEqual("LW50,200,400,20", ZebraCommands.WhiteLine(50, 200, 400, 20).ToZebraInstruction());
            Assert.AreEqual("LW10,20,30,40", ZebraCommands.WhiteLine(10, 20, 30, 40).ToZebraInstruction());
        }

        [Test]
        public void LineDrawDiagonalShouldGenerateTheProperString()
        {
            Assert.AreEqual("LS50,200,400,20,30", ZebraCommands.DiagonalLine(50, 200, 400, 20, 30).ToZebraInstruction());
            Assert.AreEqual("LS10,20,30,40,50", ZebraCommands.DiagonalLine(10, 20, 30, 40, 50).ToZebraInstruction());
        }

        [Test]
        public void BoxDrawCommandShouldGenerateTheProperString()
        {
            Assert.AreEqual("X50,200,400,20,30", ZebraCommands.DrawBox(50, 200, 400, 20, 30).ToZebraInstruction());
            Assert.AreEqual("X10,20,30,40,50", ZebraCommands.DrawBox(10, 20, 30, 40, 50).ToZebraInstruction());

        }


        [Test]
        public void BarCodeInstructionShouldGenerateTheProperString()
        {
            Assert.AreEqual("B0,1,0,0,2,3,4,B,\"abc\"",
                            ZebraCommands.BarCodeCommand(0, 1, ElementRotation.NO_ROTATION, 0, 2, 3, 4, true, "abc")
                                .ToZebraInstruction());
            Assert.AreEqual("B5,7,1,6,3,2,1,N,\"anything\"",
                            ZebraCommands.BarCodeCommand(5, 7, ElementRotation.ROTATE_90_DEGREES, 6, 3, 2, 1, false,
                                                         "anything")
                                .ToZebraInstruction());
        }
    }
}